package com.zmj.sy.mom.srv.aps.controller;


import com.zmj.sy.mom.srv.aps.bean.entity.mes.Part;
import com.zmj.sy.mom.srv.aps.bean.entity.order.Order;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseIdReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BasePageResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.dictdata.DictDataFindResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.plate.PlateDelPartReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.plate.PlatePartListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.workshop.*;
import com.zmj.sy.mom.srv.aps.config.AspectLog;
import com.zmj.sy.mom.srv.aps.config.ProjectConfig;
import com.zmj.sy.mom.srv.aps.feign.WmsApiClient;
import com.zmj.sy.mom.srv.aps.lock.BaseRepeatLock;
import com.zmj.sy.mom.srv.aps.service.DictDataService;
import com.zmj.sy.mom.srv.aps.service.GroupUserService;
import com.zmj.sy.mom.srv.aps.service.PartService;
import com.zmj.sy.mom.srv.aps.service.WorkshopService;
import com.zmj.sy.mom.srv.aps.utils.PartUtilService;
import com.zmj.sy.mom.srv.aps.utils.SyExceptionUtils;
import com.zmj.sy.mom.srv.aps.utils.SySecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

@RequiredArgsConstructor
@Api(tags = "车间")
@RestController
@RequestMapping("/workshop")
public class WorkshopController {
    private final GroupUserService groupUserService;
    private final DictDataService dictDataService;

    private final WorkshopService workshopService;

    private final WmsApiClient wmsApiClient;
    private final PartUtilService partUtilService;
    private final PartService partService;

    private final ProjectConfig projectConfig;

    @ApiOperation("看板")
    @GetMapping("/dashboard")
    public BaseListResVo<WorkshopDashboardResVo> dashboard(@RequestParam(required = false) Integer workType) {
        if (workType != null) {
            List<WorkshopDashboardResVo> dashboard = new LinkedList<>();
            List<WorkshopDashboardResVo> collect = new LinkedList<>();
            String userCode = SySecurityUtils.getUserCode();
            if (StringUtils.isNotBlank(userCode)) {
                Map<String, String> workshopTaskTitle = dictDataService.find("workshopTaskTitle").stream()
                        .collect(Collectors.toMap(DictDataFindResVo::getDictValue, DictDataFindResVo::getDictLabel));
                List<String> title = groupUserService.getUserTile(userCode);
                for (String tit : title) {
                    WorkshopDashboardResVo rr = new WorkshopDashboardResVo();
                    rr.setCode(tit);
                    rr.setTitle(workshopTaskTitle.get(tit));
                    collect.add(rr);
                }
                dashboard = workshopService.dashboard(collect);
            }
            return new BaseListResVo<>(dashboard);
        } else {

            List<DictDataFindResVo> dictDataFindResVos = dictDataService.find("workshopTaskTitle");

            List<WorkshopDashboardResVo> collect = dictDataFindResVos.stream()
                    .sorted(Comparator.comparing(DictDataFindResVo::getDictSort))
                    .map(e -> {
                        WorkshopDashboardResVo rr = new WorkshopDashboardResVo();
                        rr.setTitle(e.getDictLabel());
                        rr.setCode(e.getDictValue());
                        return rr;
                    })
                    .collect(Collectors.toList());

            List<WorkshopDashboardResVo> dashboard = workshopService.dashboard(collect);
            return new BaseListResVo<>(dashboard);
        }
    }

    /**
     * 用户修正数据
     */
/*    @GetMapping("/clearplate")
    public BaseListResVo<WorkshopDashboardResVo> clearplate() {
        workshopService.clearplate();
        return null;
    }*/
    @ApiOperation("钢板到零件 - 钢板列表")
    @GetMapping("/plateToPart")
    public BasePageResVo<WorkshopPlateToPartResVo> plateToPart(WorkshopPlateToPartReqVo reqVo) {
        return workshopService.plateToPartBySql(reqVo);
    }

    @ApiOperation("钢板到零件 - 零件列表")
    @GetMapping("/platePart")
    public BaseListResVo<WorkshopPlatePartResVo> platePart(BaseIdReqVo reqVo) {
        return workshopService.platePart(reqVo);
    }

    @ApiOperation("钢板开工")
    @PostMapping("/plateStartWork")
    @AspectLog(apiName = "钢板开工", operationType = 4)
    public BaseResVo plateStartWork(@RequestBody WorkshopPlateStartWorkReqVo reqVo) {
        if (!StringUtils.isBlank(reqVo.getStationCode()) && reqVo.getStationCode().contains("#")) {
            reqVo.setStationCode(reqVo.getStationCode().split("#")[0]);
        }
        workshopService.plateStartWorkNew(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("钢板报工(预处理、切割、分拣报工)")
    @PostMapping("/plateEndWork")
    @AspectLog(apiName = "钢板报工", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.plateCode+#reqVo.phaseCode", lockTime = 15)
    public BaseResVo plateEndWork(@RequestBody WorkshopPlateEndWorkReqVo reqVo) {
        if (!StringUtils.isBlank(reqVo.getStationCode()) && reqVo.getStationCode().contains("#")) {
            reqVo.setStationCode(reqVo.getStationCode().split("#")[0]);
        }
        workshopService.plateEndWorkNew(reqVo);
//        workshopService.plateEndWork(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("零件待装盘列表")
    @GetMapping("/partList")
    public BasePageResVo<WorkShopPartListResVo> partList(WorkShopPartListReqVo reqVo) {
        return workshopService.partList(reqVo);
    }


    @ApiOperation("零件装盘")
    @PostMapping("/packPart")
    @AspectLog(apiName = "零件装盘", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.plmid+#reqVo.phaseCode+#reqVo.palletNumber", lockTime = 5)
    public BaseResVo packPart(@RequestBody WorkshopPackPartReqVo reqVo) {
        workshopService.packPart(reqVo);
        wmsApiClient.partPage(reqVo.getPalletNumber());
        return BaseResVo.ok();
    }

    @ApiOperation("零件合盘")
    @PostMapping("/packMerge")
    @AspectLog(apiName = "零件合盘", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.initialPallet", lockTime = 5)
    public BaseResVo packMerge(@RequestBody WorkshopPackMergeReqVo reqVo) {
        workshopService.packMerge(reqVo);
        if (reqVo.getWmsFlage() == null || reqVo.getWmsFlage() != 1) {
            wmsApiClient.partPage(reqVo.getDestinationPallet());
            wmsApiClient.clearPallet(Arrays.asList(reqVo.getInitialPallet()));
        }


        return BaseResVo.ok();
    }

    @ApiOperation("托盘内的零件列表")
    @GetMapping("/partPalletList")
    public BaseListResVo<WorkShopPartPalletListResVo> partPalletList(WorkShopPartPalletListReqVo reqVo) {
        return workshopService.partPalletList(reqVo);
    }

    @ApiOperation("删除该托盘内的某个零件")
    @PostMapping("/palletClean")
    @AspectLog(apiName = "删除某个零件", operationType = 4)
    public BaseResVo palletClean(@RequestBody PlateDelPartReqVo reqVo) {
        workshopService.palletClean(reqVo, true);
        return BaseResVo.ok();
    }


    @ApiOperation("仅清空托盘，不发送三方")
    @PostMapping("/palletCleanNoThird")
    @AspectLog(apiName = "删除某个零件", operationType = 4)
    public BaseResVo palletCleanNoWms(@RequestBody WorkshopPalletCleanNoThirdReqVo reqVo) {
        workshopService.palletCleanNoWms(reqVo);
        return BaseResVo.ok();

    }

    @ApiOperation("组件到组件列表")
    @GetMapping("/componentToComponent")
    public BasePageResVo<WorkshopComponentToComponentResVo> componentToComponent(WorkshopComponentToComponentReqVo reqVo) {
        return workshopService.componentToComponent(reqVo);
    }

    @ApiOperation("零件到组件加工列表")
    @GetMapping("/partToComponent")
    public BasePageResVo<WorkshopPartToComponentResVo> partToComponent(WorkshopPartToComponentReqVo reqVo) {
        return workshopService.partToComponent(reqVo);
    }


    @ApiOperation("组件零件信息列表")
    @GetMapping("/componentPart")
    public BaseListResVo<WorkshopComponentPartResVo> componentPart(BaseIdReqVo reqVo) {
        return workshopService.componentPart(reqVo);
    }


    @ApiOperation("零件到零件列表查询")
    @GetMapping("/partToPart")
    public BasePageResVo<WorkshopPartToPartResVo> partToPart(WorkshopPartToPartReqVo reqVo) {
        return workshopService.partToPart(reqVo);
    }

    @ApiOperation("页面零件开工")
    @PostMapping("/partStartWork")
    @AspectLog(apiName = "页面零件开工", operationType = 4)
    public BaseResVo partToPartStartWork(@RequestBody WorkshopPartStartWorkReqVo reqVo) {
        workshopService.partStartWorkNew(reqVo);
        return BaseResVo.ok();
//        return workshopService.partStartWork(reqVo);
    }

    @ApiOperation("零件批量开工")
    @PostMapping("/partBatchStart")
    @AspectLog(apiName = "零件批量开工", operationType = 4)
    public BaseResVo partBatchStart(@RequestBody EmbeddedStartModel reqVo) {
        workshopService.partBatchStart(reqVo);
        return BaseResVo.ok();
//        return workshopService.partStartWork(reqVo);
    }

    /**
     * @param
     * @return
     */
    @ApiOperation("pda零件开工")
    @PostMapping("/startWorkByPart")
    @AspectLog(apiName = "pda零件开工", operationType = 4)
    public BaseResVo startWorkByPart(@RequestBody EmbeddedStartModel reqVo) {
        workshopService.startWorkByPart(reqVo);
        return BaseResVo.ok();
//        return workshopService.partStartWork(reqVo);
    }

    @ApiOperation("零件报工")
    @AspectLog(apiName = "零件报工", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.plmid+#reqVo.phaseCode+#reqVo.stationCode+#reqVo.id", lockTime = 5)
    @PostMapping("/partEndWork")
    public BaseResVo partToPartEndWork(@RequestBody WorkshopPartEndWorkReqVo reqVo) {
        if (!StringUtils.isBlank(reqVo.getUniqueCode())) {
            if (reqVo.getPartCount() > 1) {
                throw SyExceptionUtils.e("组件报工数量不能大于1");
            }
            workshopService.partEndWorkAssemble(reqVo);
        } else {
            if (StringUtils.isBlank(reqVo.getGroupCode())) {
                reqVo.setGroupCode(reqVo.getStationCode());
            }

            try {
                workshopService.partEndWorkNew(reqVo);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                //  失败，成功都进行同步零件
                if (!StringUtils.isBlank(reqVo.getPalletNumber())) {
                    wmsApiClient.partPage(reqVo.getPalletNumber());
                }
                if (!"mesPart".equals(reqVo.getStartPalletNumber()) && !reqVo.getStartPalletNumber().startsWith("D") && !org.apache.commons.lang3.StringUtils.equals(reqVo.getPalletNumber(), reqVo.getStartPalletNumber())) {
                    wmsApiClient.partPage(reqVo.getStartPalletNumber());
                }
            }

        }

        return BaseResVo.ok();
//        return workshopService.partEndWork(reqVo);
    }

/*    @ApiOperation("组件开工")
    @GetMapping("/componentStartWork")
    public BaseResVo componentToComponentStartWork(WorkshopComponentStartWorkReqVo reqVo){
        return workshopService.componentStartWork(reqVo);
    }*/

/*    @ApiOperation("组件报工")
    @GetMapping("/componentEndWork")
    public BaseResVo componentToComponentEndWork(WorkshopComponentEndWorkReqVo reqVo){
        return workshopService.componentEndWork(reqVo);
    }*/


    @ApiOperation("配盘-定时器-抓取MBD配盘数据")
    @GetMapping("/mbdPpJob")
    public BaseResVo mbdPpJob(int m, int day) {
//        LocalDate now = LocalDate.now();
        LocalDate now = LocalDate.of(2025, m, day);

        workshopService.mbdPpJob(now, null, null);
        return BaseResVo.ok();
    }

    @ApiOperation("配盘-定时器-抓取MBD配盘数据")
    @GetMapping("/mbdPpJobHand")
    public BaseResVo mbdPpJobHand(String plmId) {
        workshopService.mbdPpJob(null, plmId, null);
        return BaseResVo.ok();
    }

    @ApiOperation("待配盘的任务列表")
    @GetMapping("/matchList")
    public BaseListResVo<WorkShopMatchListResVo> matchList(WorkShopMatchListReqVo reqVo) {
        return workshopService.matchList(reqVo);
    }

    @ApiOperation("配盘-根据施工号和父件plmId抓取配盘任务")
    @PostMapping("/ppPlmId")
    public BaseResVo ppPlmId(WorkShopPpPlmIdReqVo reqVo) {
        workshopService.mbdPpJob(null, reqVo.getPlmId(), reqVo.getConstructNo());
        return BaseResVo.ok();
    }


    @ApiOperation("拼点拼装列表")
    @GetMapping("/assembleList")
    public BasePageResVo<WorkshopAssembleListResVo> assembleList(WorkshopAssembleListReqVo reqVo) {
        return workshopService.list(reqVo);
    }

    /**
     * 将料位托盘的零件转移到工位上
     */
    @ApiOperation("拼点、拼装开工")
    @PostMapping("/assembleStart")
    @AspectLog(apiName = "拼点、拼装开工", operationType = 4)
    public BaseResVo assembleStart(@RequestBody WorkshopAssembleStartReqVo reqVo) {
 /*       if(StringUtils.contains(reqVo.getStationCode(),"RGPZc_00")&&StringUtils.contains(reqVo.getAssemblyNumber(),"P1")) {
            workshopService.assembleYipingStart(reqVo);
        }else if (StringUtils.contains(reqVo.getStationCode(),"RGPZc_00")&&StringUtils.contains(reqVo.getAssemblyNumber(),"P4")){
            workshopService.assembleYipingStart(reqVo);
        }else if (StringUtils.contains(reqVo.getStationCode(),"CBPZ_00")){
            workshopService.assembleYipingStart(reqVo);
        }else{
            workshopService.assembleStart(reqVo);
        }*/
        if (reqVo.getApsWorkOrderId() != null || !StringUtils.isBlank(reqVo.getConstructNo())) {
            // 评点开工  开多个计划
            workshopService.assembleYipingStart(reqVo);
        } else {
            //  开一个计划
            workshopService.assembleStart(reqVo);
        }

        return BaseResVo.ok();
    }

    @ApiOperation("拼点、拼装报工")
    @PostMapping("/assembleEnd")
    @AspectLog(apiName = "拼点、拼装报工", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.stationCode+#reqVo.id+#reqVo.staffCode", lockTime = 5)
    public BaseResVo assembleEnd(@RequestBody WorkshopAssembleEndReqVo reqVo) {
        workshopService.assemblePdEnd(reqVo);
        if (!StringUtils.isBlank(reqVo.getPalletNumber())) {
            wmsApiClient.partPage(reqVo.getPalletNumber());
        }
        return BaseResVo.ok();
    }

    @ApiOperation("Pda拼点、拼装报工")
    @PostMapping("/assemblePdaEnd")
    @AspectLog(apiName = "Pda拼点、拼装报工", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.stationCode+#reqVo.id+#reqVo.quantity", lockTime = 5)
    public BaseResVo assemblePdaEnd(@RequestBody WorkshopAssembleEndReqVo reqVo) {
        workshopService.assemblePdaEnd(reqVo);
        return BaseResVo.ok();
    }

/*    @ApiOperation("测试通知wms")
    @GetMapping("/sysWms")
    public BaseResVo sysWms() {
        workshopService.sysWms();

        return BaseResVo.ok();
    }*/


    @ApiOperation("组件报工")
    @AspectLog(apiName = "组件报工", operationType = 4)
//    @BaseRepeatLock(lockKey = "#reqVo.plmid+#reqVo.phaseCode+#reqVo.stationCode+#reqVo.id", lockTime = 10)
    @PostMapping("/componentEndWork")
    public BaseResVo componentEndWork(@RequestBody WorkshopPartEndWorkReqVo reqVo) {
        if (!StringUtils.isBlank(reqVo.getUniqueCode())) {
            if (reqVo.getPartCount() > 1) {
                throw SyExceptionUtils.e("组件报工数量不能大于1");
            }
            if (StringUtils.isBlank(reqVo.getGroupCode())) {
                reqVo.setGroupCode(reqVo.getStationCode());
            }
            workshopService.partEndWorkAssemble(reqVo);
        } else {
            throw SyExceptionUtils.e("组件报工，缺少唯一编号");
        }

        return BaseResVo.ok();
//        return workshopService.partEndWork(reqVo);
    }

    @ApiOperation("组件拼装报工")
    @PostMapping("/assemblePzEnd")
    @AspectLog(apiName = "组件拼装报工", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.assemblyNumber+#reqVo.uniqueCode+#reqVo.workPlaceName", lockTime = 10)
    public BaseResVo assemblePzEnd(@RequestBody WorkshopAssemblePzEndReqVo reqVo) {
        workshopService.assemblePzEnd(reqVo);
        return BaseResVo.ok(reqVo.getUniqueCode());
    }

    @ApiOperation("外购件入库")
    @PostMapping("/partIn")
    @AspectLog(apiName = "外购件入库", operationType = 4)
    public BaseResVo partIn(@RequestBody WorkshopPartInReqVo reqVo) {
        workshopService.partIn(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("钢板到达")
    @PostMapping("/plateIn")
    @AspectLog(apiName = "钢板到达", operationType = 4)
    public BaseResVo plateIn(@RequestBody WorkshopPlateInReqVo reqVo) {
        workshopService.plateIn(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("钢板离开")
    @PostMapping("/plateOut")
    @AspectLog(apiName = "钢板离开", operationType = 4)
    public BaseResVo plateOut(@RequestBody WorkshopPlateOutReqVo reqVo) {
        // 为了适配钢板库特殊处理
        if (StringUtils.isNotBlank(reqVo.getPlmId())) {
            reqVo.setPlateCode(reqVo.getPlmId());
        }
        if (StringUtils.isNotBlank(reqVo.getPositionCode())) {
            if (reqVo.getPositionCode().contains("#")) {
                reqVo.setStationCode(reqVo.getPositionCode().split("#")[0]);
            } else {
                reqVo.setStationCode(reqVo.getPositionCode());
            }
        }
        workshopService.plateOut(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("pda、页面分拣报工")
    @PostMapping("/plateFjEndWork")
    @AspectLog(apiName = "pda分拣报工", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.partCode+#reqVo.phaseCode+#reqVo.staffCode", lockTime = 10)
    public BaseResVo plateFjEndWork(@RequestBody WorkshopPlateFjEndWorkReqVo reqVo) {
        if (reqVo.getFailCount() == null) {
            reqVo.setFailCount(0);
        }


        if (StringUtils.isBlank(reqVo.getPhaseCode())) {
            reqVo.setPhaseCode("FJ");
        }
        workshopService.platePdaFjEndWork(reqVo);
        if (!StringUtils.isBlank(reqVo.getPalletCode())) {
            wmsApiClient.partPage(reqVo.getPalletCode());
        }
        return BaseResVo.ok();
    }

    @ApiOperation("待开工的零件列表")
    @GetMapping("/platePartList")
    public BasePageResVo<PlatePartListResVo> platePartList(WorkshopPlatePartListReqVo reqVo) {
        if (reqVo.getStatus() != null && reqVo.getStatus() == 3) {
            return workshopService.platePartEndList(reqVo);
        } else {
            return workshopService.platePartList(reqVo);
        }

    }


    @ApiOperation("pda配盘开工")
    @PostMapping("/matchStart")
    @AspectLog(apiName = "pda配盘开工", operationType = 4)
    public BaseResVo matchStart(@RequestBody WorkshopMatchStartReqVo reqVo) {
        workshopService.matchStart(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("页面配盘-开工")
    @PostMapping("/matchStartWork")
    @AspectLog(apiName = "页面配盘-开工", operationType = 4)
    @Deprecated
    public BaseResVo matchStartWork(@RequestBody WorkShopMatchStartWorkReqVo reqVo) {
        workshopService.matchStartWork(reqVo);
        return BaseResVo.ok();
    }

/*
    @ApiOperation("页面配盘-报工")
    @PostMapping("/matchEndWork")
    @AspectLog(apiName = "页面配盘-报工", operationType = 4)
    @Deprecated
    public BaseResVo matchEndWork(@RequestBody WorkShopMatchEndWorkReqVo reqVo) {
        workshopService.matchEndWork(reqVo);
        if (!StringUtils.isBlank(reqVo.getPalletCode())) {
            wmsApiClient.partPage(reqVo.getPalletCode());
        }
        return BaseResVo.ok();
    }
*/

    @ApiOperation("pda配盘报工")
    @PostMapping("/matchEnd")
    @AspectLog(apiName = "pda配盘报工", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.matchcNo+#reqVo.palletNumber+#reqVo.storageNumber", lockTime = 5)
    public BaseResVo matchEnd(@RequestBody WorkshopMatchEndReqVo reqVo) {
        workshopService.matchEnd(reqVo);
        try {
            wmsApiClient.ppPartPage(reqVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return BaseResVo.ok();
    }

    @ApiOperation("托盘查询配盘历史 最近十条")
    @GetMapping("/ppHistory")
    public BaseListResVo<WorkshopPpHistoryResVo> ppHistory(WorkshopPpHistoryReqVo reqVo) {
        return workshopService.ppHistory(reqVo);
    }

    @ApiOperation("托盘绑定")
    @PostMapping("/trayBind")
    @AspectLog(apiName = "托盘绑定", operationType = 4)
    public BaseResVo trayBind(@RequestBody WorkshopTrayBindReqVo reqVo) {
        workshopService.trayBind(reqVo);
        wmsApiClient.clearPallet(Arrays.asList(reqVo.getTrayCode()));
        return BaseResVo.ok();
    }


    @ApiOperation("托盘解绑")
    @PostMapping("/trayUnbind")
    @AspectLog(apiName = "托盘解绑", operationType = 4)
    public BaseResVo trayUnbind(@RequestBody WorkshopTrayUnbindReqVo reqVo) {
        workshopService.trayUnbind(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("领料单 - 查询领料单钢板套料明细")
    @GetMapping("/getPickDetail")
    public WorkshopGetPickDetailResVo getPickDetail(WorkshopGetPickDetailReqVo reqVo) {
        return workshopService.getPickDetail(reqVo);
    }

    @ApiOperation("喷涂 - 查询组件信息")
    @GetMapping("/getSprayMesMateria")
    public List<SprayMesMaterialDto> getSprayMesMateria() {
        return workshopService.getSprayMesMateria();
    }

    /**
     * 补套料漏调的零件
     *
     * @param
     * @return
     */
    @ApiOperation("分拣报工后补充零件")
    @PostMapping("/fixPartTaskCreate")
    public BaseResVo fixPartTaskCreate(@RequestParam(value = "钢板编号") List<String> plateList, @RequestParam(value = "订单id") String orderId, @RequestParam String password) {
        if ("031392".equals(password)) {
            for (String plate : plateList) {
                workshopService.fixPartTaskCreate(plate, orderId);
            }
        } else {
            return BaseResVo.fail("密码错误");
        }
        return BaseResVo.ok();
    }


    @ApiOperation("获取零件信息")
    @GetMapping("/getPart")
    public Part getPart(String constructNo, String plmid, String phaseCode) {
        return partService.getPart(constructNo, plmid, phaseCode);
    }

    @ApiOperation("在制品无中生有，并增加相应的任务和计划 - 张迪")
    @PostMapping("/addPartNew")
    public BaseResVo addPartNew(@Validated @RequestBody AddPartDto dto) {

        if (!projectConfig.isAddPartFlag()) {
            throw SyExceptionUtils.e("该接口已禁用!");
        }

        if ("032240".equals(dto.getPassword())) {
            workshopService.addPart(dto.getPlmid().trim(), dto.getPhaseCode(), dto.getCount(), dto.getConstructNo().trim());
        } else {
            return BaseResVo.fail("密码错误");
        }
        return BaseResVo.ok();
    }

    @ApiOperation("零件齐套性检查")
    @GetMapping("/checkdPart")
    public BaseListResVo<CheckdPartVo> checkdPart(@RequestParam String plmid) {
        List<CheckdPartVo> checkdPartVoList = workshopService.checkdPart(plmid);
        return BaseListResVo.of(checkdPartVoList, CheckdPartVo.class);
    }


    @ApiOperation("填补mes的报工记录")
    @PostMapping("/buWorkRecord")
    public BaseResVo buWorkRecord(@RequestBody List<String> plateList) {
        workshopService.buWorkRecord(plateList);
        return BaseResVo.ok();
    }

    @ApiOperation("赋码到组件-列表")
    @GetMapping("/fmToComponentList")
    public BasePageResVo<WorkShopFmToComponentListResVo> fmToComponentList(WorkShopFmToComponentListReqVo reqVo) {
        return workshopService.fmToComponentList(reqVo);
    }

    @ApiOperation("赋码到组件-开工")
    @PostMapping("/fmToComponentStart")
    public BaseResVo fmToComponentStart(@RequestBody BaseIdReqVo reqVo) {
        workshopService.fmToComponentStart(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("赋码到组件-报工")
    @PostMapping("/fmToComponentEnd")
    public BaseResVo fmToComponentEnd(@RequestBody WorkShopFmToComponentEndReqVo reqVo) {
        workshopService.fmToComponentEnd(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("查询订单信息")
    @GetMapping("/workshop/getOrder")
    Order getOrder(@RequestParam("constructionNo") String constructionNo, @RequestParam("plmid") String plmid) {
        return workshopService.getOrder(constructionNo, plmid);
    }
}
